package sany.cxp.rabbitmq.service;

import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

/**
 * @Author: Thomas
 * @Date: 2024-01-21  19:42:53
 * @Description:
 */
@Service
@RabbitListener(queues = {"zm.queue"})
@Slf4j
public class Consumer {

    int index = 1;

    @RabbitHandler
    public void getMessage(String message) throws InterruptedException {
        log.info("email: {}", message);
        /**
         * 解决消息无限重试的方案：
         * 1. 通过application.yml配置重试的次数 + 死信队列；
         * 2. try catch 手动ack
         * 3. try catch 手动ack 死信队列 人工干预
         */
        if (index % 20 != 0) {
            index++;
            log.info("index === {}", index);
            int a = 1 / 0;
        }
        Thread.sleep(20000);
    }

}
